<?php

declare(strict_types=1);

namespace app\shop\controller\api;

use think\Request;
use think\facade\Log;
use think\facade\Db;
use sheep\exception\SheepException;
use app\shop\model\Withdraw as WithdrawModel;
use app\shop\service\Withdraw as WithdrawLibrary;

class Withdraw extends ShopBase
{

    public function index() 
    {
        $user = $this->auth()->user();
        $withdraws = WithdrawModel::where(['user_id' => $user->id])->hidden(['withdraw_info'])->order('id desc')->paginate(request()->param('list_rows', 10));

        return success('获取成功', $withdraws);
    }


    // 提现规则
    public function rules()
    {
        $user = $this->auth()->user();
        $config = (new WithdrawLibrary($user))->config;

        return success('提现规则', $config);
    }


    // 发起提现请求
    public function apply(Request $request)
    {
        $user = $this->auth()->user();
        $params = $request->param();

        $this->svalidate($params, ".apply");

        $withdrawLib = new WithdrawLibrary($user);
        $withdraw = $withdrawLib->apply($params);

        return success('申请成功', $withdraw);
    }
}
